using System;
using System.Threading;

using Dashboard;
using Dashboard.Util;
using Dashboard.Engine;

namespace Dashboard.Sidebar
{
	public class Driver
	{
		public static void Main (string [] args)
		{
			SystemInformation.SetProcessName ("dashboard");
			Gnome.Program program = new Gnome.Program ("Dashboard", "0.0.1", Gnome.Modules.UI, args);
					       
			ThreadAssist.Initialize ();

			// FIXME: We should add some way for the client 
			// to connect to the engine over any of the available
			// transports.

			// Initialize the engine. 

			Dashboard.Engine.Engine.Initialize ();

			// Determine if we're being started by the 
			// applet factory as a panel applet or not.
			// If we are, register our applet, otherwise
			// just launch a standalone window containing
			// the sidebar (just for debug).

			foreach (string arg in args) {
				if (arg.StartsWith ("--oaf-activate-iid")) {
					//_Gnome.PanelAppletFactory.Register (typeof (Applet));
					return;
				}
			}
			
			Sidebar sidebar = new Sidebar ();
			sidebar.Destroyed += delegate {
				Dashboard.Engine.Engine.Dispose ();
				program.Quit ();
			};

			sidebar.ShowAll ();

			program.Run ();
		}
	}
}
